package com.ckjava.test.config;

import com.ckjava.test.filter.CorsFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * 自动将 `src\main\resources\webStatic` 目录的文件映射到 /**
         * /** 表示匹配任意层级的目录和文件
         */
        //registry.addResourceHandler(new String[]{"/**"}).addResourceLocations("classpath:/webStatic/").setCacheControl(CacheControl.noCache());

        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }


    /**
     * 注册 cors filter
     * @return
     */
    /*@Bean
    public FilterRegistrationBean someFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new CorsFilter());
        registration.addUrlPatterns("/api/*");
        registration.setName("corsFilter");
        registration.setOrder(1);
        return registration;
    }*/
}
